import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import postcssPxToViewport from "postcss-px-to-viewport";
import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
  base: "/",
  plugins: [react()],
  css: {
    postcss: {
      plugins: [
        postcssPxToViewport({
          viewportWidth: 750, // 设计稿的宽度
          unitPrecision: 5,
          viewportUnit: "vw",
          selectorBlackList: ["ignore", ".ignore"], // 忽略转换的类名
          minPixelValue: 1,
          mediaQuery: false, // 是否在媒体查询中转换px
          exclude: /([/\\])(node_modules)([/\\])/, // 排除node_modules中的文件
        }),
      ],
    },
    modules: {
      scopeBehaviour: "local",
      generateScopedName: "[name]_[local]__[hash:base64:5]",
    },
  },
  server: {
    proxy: {
      "/web": {
        target: "http://127.0.0.1:8000",
      },
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
});
